#include<bits/stdc++.h>
#define N 100002
using namespace std;
int s,n,m,l,V,sum,maxn=-100;
struct node{
    int d;
    int v;
    int a;
}t[N];
int p[N];
int main()
{
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>s;
    for(int j=1;j<=s;j++){
        cin>>n>>m>>l>>V;
        for(int i=1;i<=n;i++){
            cin>>t[i].d>>t[i].v>>t[i].a;
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            maxn=max(maxn,p[i]);
        }
        for(int i=1;i<=n;i++){
            if(t[i].d<=maxn){
                if(t[i].v>V)
                    sum++;
            }
        }
        cout<<sum<<" "<<m-1<<endl;
        sum=0;
    }
    return 0;
}
